<?php

/**
 * Add a notification for a specific user
 *
 * @since WebApper (1.0)
 * @param int $item_id
 * @param string $type
 * @param string $short_message
 * @param string $long_message
 * @param int $user_id
 * @param int $created_on
 * @param bool $notified
 * @return boolean True on success, false on fail
 */
function web_apper_add_notification( $item_id, $type, $short_message, $long_message, $user_id, $created_on, $notified = false ) {
		
	$notified_on = ( $notified != false ) ? current_time('timestamp') : null;

	$notification                   = new WebApper\Notification\Notification;
	$notification->item_id          = $item_id;
	$notification->type          	= $type;
	$notification->short_message	= $short_message;
	$notification->long_message    	= $long_message;
	$notification->user_id          = $user_id;
	$notification->is_new           = 1;
	$notification->created_on	    = current_time('timestamp');
	$notification->notified_on	    = $notified_on;

	if ( $notification->save() )
		return true;

	return false;
}

/**
 * Get notifications for a specific user
 *
 * @since WebApper (1.0)
 * @param int $user_id
 * @return boolean Object or array on success, false on fail
 */
function web_apper_get_notifications_for_user( $user_id ) {
	return $notifications = WebApper\Notification\Notification::get_all_for_user( $user_id );
}

/**
 * Delete notifications for a user by type
 *
 * Used when clearing out notifications for a specific component when the user
 * has visited that component.
 *
 * @since WebApper (1.0)
 * @param int $user_id
 * @param string $type
 * @return boolean True on success, false on fail
 */
function web_apper_delete_notifications_by_type( $user_id, $type ) {
	return WebApper\Notification\Notification::delete_for_user_by_type( $user_id, $type );
}

/**
 * Delete notifications for an item ID
 *
 * Used when clearing out notifications for a specific component when the user
 * has visited that item.
 *
 * @since WebApper (1.0)
 * @param int $user_id
 * @param string $type
 * @param int $item_id
 * @return boolean True on success, false on fail
 */
function web_apper_delete_notifications_by_item_id( $user_id, $type, $item_id ) {
	return WebApper\Notification\Notification::delete_for_user_by_item_id( $user_id, $type, $item_id );
}

/**
 * Delete notifications for an ID
 *
 * @since WebApper (1.0)
 * @param int $ID
 * @return boolean True on success, false on fail
 */
function web_apper_delete_notifications_by_id( $ID ) {
	return WebApper\Notification\Notification::delete_by_id( $ID );
}

?>